package com.sc.nft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.dao.MallActivityRankingCyclesDao;
import com.sc.nft.dao.MallActivityRankingDao;
import com.sc.nft.entity.MallActivityRanking;
import com.sc.nft.entity.MallActivityRankingCycles;
import com.sc.nft.entity.vo.MallActivityRankingCyclesVO;
import com.sc.nft.mapstruct.MallActivityRankingCyclesMapStruct;
import com.sc.nft.service.MallActivityRankingCyclesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 排行榜周期配置
 *
 * @author zxy
 * @description IP商城
 * @since 2023-05-10 16:59:01
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class MallActivityRankingCyclesServiceImpl implements MallActivityRankingCyclesService {

    private final MallActivityRankingCyclesDao mallActivityRankingCyclesDao;

    private final MallActivityRankingDao mallActivityRankingDao;


    @Override
    public List<MallActivityRankingCycles> queryActivityRankingCyclesList(Long rankingId) {
        LambdaQueryWrapper<MallActivityRankingCycles> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallActivityRankingCycles::getRankingId, rankingId);
        return mallActivityRankingCyclesDao.list(wrapper);
    }

    @Override
    public List<MallActivityRankingCyclesVO> queryActivityRankingCyclesList() {
        MallActivityRanking mallActivityRanking = mallActivityRankingDao.getMallActivityRanking();
        if(mallActivityRanking == null){
            return null;
        }
        LambdaQueryWrapper<MallActivityRankingCycles> rankingCyclesWrapper = new LambdaQueryWrapper<>();
        rankingCyclesWrapper.eq(MallActivityRankingCycles::getIsDelete,false);
        rankingCyclesWrapper.le(MallActivityRankingCycles::getStartTime, new Date());
        rankingCyclesWrapper.eq(MallActivityRankingCycles::getRankingId, mallActivityRanking.getId());
        rankingCyclesWrapper.orderByDesc(MallActivityRankingCycles::getStartTime);
        return MallActivityRankingCyclesMapStruct.INSTANCE.mallActivityRankingCyclesList2VO(mallActivityRankingCyclesDao.list(rankingCyclesWrapper));
    }


}